Skip to content

Plugins: load only official LeanBitLab plugins, checked before anything is extracted - #1025

Open
4di-hello wants to merge 2 commits into
LeanBitLab:mainfrom
4di-hello:pr/plugin-trust
Open

4di-hello wants to merge 2 commits into
LeanBitLab:mainfrom
4di-hello:pr/plugin-trust

Conversation

@4di-hello

Copy link
Copy Markdown
Contributor

Why

The AI, translation, OCR, handwriting and CJK plugins are APK files the user picks; their code is loaded with DexClassLoader into the keyboard process, where it sees everything that is typed. Today any APK is loaded. A fake "plugin" from some download site would run as part of the keyboard.

What changes

  • PluginTrust.requireTrusted() before any plugin file is extracted or loaded, on every load and import path (AI, translation, OCR, handwriting, CJK). Accepted:
    • APKs signed with a known LeanBitLab key. I read the certificates of all plugin releases on GitHub with apksigner: CJK, GIF and translation 01cfc721…, OCR, AI and handwriting from 1.0.7 963156a0…, voice c537f494…;
    • or with the keyboard's own signing key (builds that sign keyboard and plugins with one key);
    • or one of the unsigned handwriting releases 1.0.0–1.0.6 (by their SHA-256), so existing installations keep working.
  • One signer: a trusted key anywhere in its key history is enough (key rotation stays possible). Several signers: all must be trusted.
  • Refused: a message "Plugin not loaded: (reason)" (once per file), nothing of the plugin is extracted or loaded.
  • Voice plugin: the app is only bound if it is signed with a known key. (The GIF plugin already has its own check.)
  • File names from the plugin archive are used without their path, so an entry like lib/arm64-v8a/../../x.so can't leave the plugin folder.
  • Unit test for packages that aren't installed and for the own package.

Please check

  • A new plugin key (or a new unsigned handwriting release) needs its SHA-256 in PluginTrust; otherwise that plugin is refused with the message above. Signing every plugin keeps this simple.
  • Android 6 reads only v1 (JAR) signatures from an APK file. If a plugin release is signed with v2/v3 only, it is refused on Android 6.

How we tested

Compiles. The same check runs in my fork (LeanType+) since 27.10.; there I use the AI and voice plugins with it, the other plugins I only checked against the signatures of their releases. An independent review (Claude) found two import paths I had missed in this port (translation and handwriting import) and a likely Android 9 issue with the signature flags; both are fixed in this PR. Not tested on Android 6 or 9 devices.

🤖 Generated with Claude Code

4di-hello and others added 2 commits November 30, 2026 20:14
…ng is extracted

Plugins run inside the keyboard and see everything that is typed, but any APK a user picks was loaded.
Now the AI, translation, OCR, handwriting and CJK plugins are checked before extraction: signed with a
known LeanBitLab key (or the keyboard's own key), or one of the known unsigned handwriting releases
1.0.0-1.0.6. The voice plugin app is only bound when it has a known key. File names from the plugin
archive are used without their path, so an entry like "../x.so" can't leave the plugin folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…9, key rotation, message once

- Translation import and the handwriting class loader (every load and import) are checked as well
- Signatures are read with GET_SIGNATURES and GET_SIGNING_CERTIFICATES (Android 9 fills signingInfo
  only with the first in some versions)
- One signer: a trusted key anywhere in its history is enough (key rotation); several signers: all
- A refused file or app is not checked again in this process and its message is shown once
- Messages as string resources

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant